<?php
header("Content-Type:text/html;charset=utf-8");
require '../php_func/mysql.php';
session_start();
if($_GET["liebiao_init"]){
	$user=$_SESSION["login"];
	$xml=new DOMDocument();
	$xml->load("../user/$user/love.xml");
	$subject=$xml->getElementsByTagName("subject")->item(0);
	$arr=array();
	$child=$subject->childNodes;
	foreach ($child as $i){
		if($i->nodeName=="sub"){
			$arr_tmp=array();
			$id=$i->getAttribute("id");
			$arr_tmp["id"]=$id;
			$arr_tmp["title"]=$i->nodeValue;
			array_push($arr,$arr_tmp);
		}
	}
	echo json_encode($arr);
}else if($_GET["del_sub"]){
	$id=$_GET["id"];
	$user=$_SESSION["login"];
	$filepath="../user/$user/love.xml";
	$xml=new DOMDocument();
	$xml->load($filepath);
	$root=$xml->documentElement;
	$subject=$xml->getElementsByTagName("subject")->item(0);
	$xpath=new DOMXPath($xml);
	$sub=$xpath->query("subject/sub[@id='$id']")->item(0);
	$sub->parentNode->removeChild($sub);
	$love=$xpath->query("love[@id='$id']")->item(0);
	$love->parentNode->removeChild($love);
	$xml->save($filepath);
	echo "ok";
}else if($_GET["change_psd"]){
	$old=$_GET["old"];
	$new_psd=$_GET["new_psd"];
	$user=$_SESSION["login"];
	$sql="select * from users where mail='$user'";
	$result=mysql_query($sql);
	$row=mysql_fetch_assoc($result);
	if($old=$row["password"]){
		$sql="update users set password ='$new_psd' where mail='$user'";
		$result=mysql_query($sql);
		if(mysql_affected_rows()>0){
			echo "ok";
		}else{
			echo "fail";
		}
	}else{
		echo "again";
	}
	mysql_close();
}
?>